<!DOCTYPE html>
<!--<html lang="en" xmlns:th="http://www.thymeleaf.org">-->
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<script type="text/javascript" th:src="@{/jquery/jquery-1.11.1-min.js}"></script>
<!--<script type="text/javascript" th:src="@{/jquery/jquery.js}"></script>-->
<body>
<form action="/user/registry" method="post">
    用户名:<input type="text" id="username" name="username" /> <br>
    用户密码:<input type="password" id="password" name="password" /><br>
    邮箱:<input type="email" name="email" id="email"/><br>
    注册码:<input type="text" name="vcode" /> <input type="button" value="获取注册码" id="vcode"><br> <!-- 这里使用异步的方式进行获取注册码 -->
    <input type="submit" value="注册" />
</form>


<script>
    $(function (){

        $("#vcode").click(function (){
            var email = $("#email").val()
            console.log(email)
            if (email==""){
                alert("请填写邮箱再进行获取注册码")
            }else {
                getVcode();
            }
        })

        function getVcode () {
            var username = $("#username").val()
            var password = $("#password").val()
            var email = $("#email").val()
            $.ajax({
                url: "/user/getCode",
                type: "post",
                data: {
                    "username": username,
                    "password": password,
                    "email":email
                },
                dataType: "json",
                success: function (data) {
                    if (data.success == true) {
                      alert("注册码成功发到邮箱");
                    }
                }
            })
        }




        })
</script>
</body>
</html>